/// ShaderManager.h
/// Matthew DiBernardo (Cryptex)
/// 07.28.09
///
/// Defines the ShaderManager.h class, which is designed to
/// handle the storage and simplify the usage of shaders within
/// a 3D application.

#ifndef _SHADERMANAGER_H_
#define _SHADERMANAGER_H_

#include "Shader.h"
#include <map>
#include <string>

#include "ShaderFactory.h"

#define SM_MAXSHADERS 20
#define MAX_SHADER_PASSES 3

class ShaderManager
{
private:
	std::map<std::string, unsigned int> nameMap;
	std::map<unsigned int, Shader*> shaderMap;

	ShaderFactory shaderFac;

	unsigned int m_lastID; // Last ID generated from MakeNewID()

	// MakeNewID()
	// -- Finds a new unique ID to assign to a shader
	unsigned int MakeNewID(void);

	ShaderManager() : m_lastID(0) { shaderFac.Initialize(); }
	ShaderManager(const ShaderManager&) : m_lastID(0) {}
	ShaderManager& operator=(const ShaderManager&) {}

public:
	// Instance()
	// -- Returns the instance of the singleton.
	static ShaderManager& Instance(void);
	~ShaderManager() { Clear(); }

	// Clear()
	// -- Clears everything out of the ShaderManager
	void Clear(void);

	// ReleaseAllShaders()
	// -- Use this to clear out all shaders from the render context
	void ReleaseAllShaders(void);


	// GetID()
	// -- Retrieves an id for a particular shader from internal storage.
	// Input: fileName - The filename of the ID to retrieve
	unsigned int GetID(std::string fileName);

	// GetFileName() *DEPRECATED*
	// -- Retrieves the filename for a particular shader, given that shader's ID.
	// Input: shaderID - The ID of the shader to retrieve.
	//std::string GetFileName(unsigned int shaderID); // DEPRECATED

	// GetShader()
	// -- Retrieves a pointer to the shader with the specified ID.
	// Input: shaderID - The ID of the shader to retrieve.
	Shader* GetShader(unsigned int shaderID);

	// GetShader()
	// -- Retrieves a pointer to the shader with the specified fileName.
	// Input: fileName - The filename of the shader to retrieve.
	Shader* GetShader(std::string fileName);
};

#endif